package com.zhuzi.common.utils;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;

import java.util.List;

/**
 * @author zhuzi
 * 2022/9/13 16:08
 */
public class StringUtil extends org.apache.commons.lang3.StringUtils {

    /**
     * 包含任意
     *
     * @param cs                  搜索关键字
     * @param searchCharSequences 搜索字符序列
     * @return boolean
     */
    public static boolean containsAny(final String cs, final List<String> searchCharSequences) {
        if (isEmpty(cs) || CollectionUtils.isEmpty(searchCharSequences)) {
            return false;
        }
        for (final CharSequence searchCharSequence : searchCharSequences) {
            if (contains(cs, searchCharSequence)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 包含全部字符串
     *
     * @param cs                  检索的字符串
     * @param searchCharSequences 搜索的关键字
     * @return
     */
    public static boolean containAll(final String cs, final List<String> searchCharSequences) {

        for (String charSequence : searchCharSequences) {
            if (!contains(cs, charSequence)) {
                return false;
            }
        }
        return true;
    }

    /**
     * 所有不是空白
     */
    public static boolean isAllNotBlank(final CharSequence... css) {
        if (ArrayUtils.isEmpty(css)) {
            return false;
        }
        for (final CharSequence cs : css) {
            if (isBlank(cs)) {
                return false;
            }
        }
        return true;
    }

    public static String center(String str, final int size, final String padChar, final String rightPad) {
        if (str == null || size <= 0) {
            return str;
        }
        final int strLen = str.length();
        final int pads = size - strLen;
        if (pads <= 0) {
            return str;
        }
        str = leftPad(str, strLen + pads / 2, padChar);
        str = rightPad(str, size, rightPad);
        return str;
    }

    public static String centerEmoji(String str, final int size, final String padChar, final String rightPad) {
        if (str == null || size <= 0) {
            return str;
        }
        final int strLen = str.length();
        final int pads = size - strLen;
        if (pads <= 0) {
            return str;
        }
        int num = (size - strLen) / 4;
        return repeat(padChar, num) + str + repeat(rightPad, num);

    }
}
